export default {
    stringValidator:(rule,value,callback)=>{
        if(!rule.required)
            return  true;
        if((!value&&value!=0)||value===''){
            return false;
        }else{
            if(typeof value == 'number'){
                return (value+'').length>0;
            }
            if(Array.isArray(value)){
                return value.length>0;
            }
            return true;
        }
    },
    arrayValidator:(rule,value,callback)=>{
        if(!rule.required)
            return  true;
        if(!value||value.length==0){
            return false
        }else{
            return true;
        }
    },
    mobileValidator:(rule,value,callback)=>{
        var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
        if(!value||value.length==0){
            return true;
        }else{
            return myreg.test(value);
        }
    },
    dateValidator:(rule,value,callback)=>{
        if(!rule.required)
            return  true;
        if(!value||value==null||value==undefined||value==''){
            return false
        }else{
            return true;
        }
    },
    dateRangeValidator:(rule,value,callback)=>{
        if(!rule.required)
            return  true;
        if(!value||value.length==0){
            return false
        }else{
            if(value[0]==''||value[1]==''){
                return false;
            }
            return true;
        }
    },
    decimalValidator:(rule,value,callback)=>{
        var myreg= /^(\.*)(\d+)(\.?)(\d{0,2}).*$/g;
        if(!value||value.length==0){
            return true;
        }else{
            return myreg.test(value);
        }
    },
    scaleValidator:(rule,value,callback)=>{
        if(!value||value.length==0){
            return true;
        }else{
            var myreg = /^(((\d|[1-9]\d)(\.\d{1,2})?)|100|100.0|100.00)$/;//0-100的两位小数数子
            return myreg.test(value);
        }
    },
    numAndLetterValidator:(rule,value,callback)=>{
        var myreg = /^\w+$/;//只能输入字母、数字、下划线
        if(!value||value.length==0){
            return true;
        }else{
            if (!myreg.test(value)) {
                callback(new Error("只能输入字母、数字、下划线"))
            } else {
                callback();
            }
        }
    },
}
